package com.example.wl.tiaoyinqi.yueqifragments;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.example.wl.tiaoyinqi.MyCallbacks;
import com.example.wl.tiaoyinqi.QinxianView;
import com.example.wl.tiaoyinqi.R;

/**
 * Created by wl on 2016/5/30.
 */
public abstract class HengxianYueqiFragmen extends Fragment {
    private MyCallbacks mCallbacks;

    abstract int getLayoutResId();

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mCallbacks = (MyCallbacks) context;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mCallbacks = null;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(getLayoutResId(), container, false);
        QinxianView qinxianView = (QinxianView) v.findViewById(R.id.qinxianView);
        qinxianView.setLeftMargin(getLeftMargins());
        qinxianView.setLeftTopMargin(getLeftTopMargins());
        qinxianView.setRightTopMargin(getRightTopMargins());
        qinxianView.setQinzhenLeftMargin(getQinzhenLeftMargins());
        qinxianView.setOnXianClickListener(new QinxianView.onXianClickListener() {
            @Override
            public void xianClick(int position) {
                mCallbacks.onXianClick(position);
            }
        });
        return v;
    }

    public int[] getLeftMargins() {
        return new int[]{
                410, 309, 225, 160, 112,
                77, 49, 29, 18, 17,
                27, 46, 78, 126, 187
        };
    }

    public int[] getLeftTopMargins() {
        return new int[]{
                1663, 1567, 1472, 1377, 1283,
                1188, 1092, 998, 902, 806,
                713, 617, 522, 427, 333
        };
    }

    public int[] getRightTopMargins() {
        return new int[]{
                1627, 1520, 1413, 1325, 1231,
                1147, 1070, 1004, 928, 853,
                787, 717, 628, 549, 455
        };
    }

    public int[] getQinzhenLeftMargins(){
        return new int[15];
    }
}
